package com.example.demo.concurrent.MyThreadPool2;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-03-28
 * Time: 14:27
 */
@Slf4j(topic = "c.TestDemo3")
public class TestDemo3 {

    public static void main(String[] args){
        ExecutorService service = Executors.newFixedThreadPool(2);
        service.submit(()->{
            log.debug("task1 start");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("task1 end");
            return "1";
        });
        service.submit(()->{
            log.debug("task2 start");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("task2 end");
            return "2";
        });
        service.submit(()->{
            log.debug("task3 start");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("task3 end");
            return "3";
        });

        log.debug("shutdownnow");
        List<Runnable> runnables = service.shutdownNow();
        log.debug("未执行的任务{}",runnables);
    }

}
